package com.qf.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdScheduler;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.io.IOException;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/9/1 20:51
 */
@EnableScheduling//开启任务调度注解
public class Demo {
    private ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

    @Test
    @Scheduled(cron = "0/2 * * * * ?")
//    @Scheduled(fixedRate = 2)//开启任务触发注解,几秒触发一次,与fixedDelay = 2相似,不过fixedRate不受任何事务影响而延迟
    public void test01() throws SchedulerException, IOException {
        StdScheduler scheduler = (StdScheduler) context.getBean("scheduler");
//        暂停
        scheduler.pauseJob(JobKey.jobKey("job1", "job_group1"));

//        恢复
        scheduler.resumeJob(JobKey.jobKey("job1", "job_group1"));

        System.out.println(scheduler.getClass());
//        System.in.read();
    }

}
